package com.atguigu.zy.interview.juc.atomics;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author : Jungle
 * @Description :  原子引用类型
 */

@Data
@AllArgsConstructor
class User {
    String userName;
    int age;

}

public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User z3 = new User("z3", 22);
        User li4 = new User("li4", 25);
        AtomicReference<User> reference = new AtomicReference<>();
        reference.set(z3);
        System.out.println(reference.compareAndSet(z3, li4) + "\t" + reference.get().toString());
        System.out.println(reference.compareAndSet(z3, li4) + "\t" + reference.get().toString());
    }
}
